package com.liunian.algorithmstudy.tree;

public class IsSymmetric101 extends TreeNode {

	public boolean isSymmetric(TreeNode root) {
		return travelsal(root.left, root.right);
	}

	private boolean travelsal(TreeNode left, TreeNode right) {
		if (left == null && right == null) {
			return true;
		} else if (left == null && right != null) {
			return false;
		} else if (left != null && right == null) {
			return false;
		} else if (left.val != right.val) {
			return false;
		}
		boolean isSame1 = travelsal(left.left, right.right);
		boolean isSame2 = travelsal(left.right, right.left);
		return isSame1 && isSame2;
	}

}
